//主函数执行区间
#include "painter.h"
#include "ui_painter.h"
#include <QGraphicsItem>
#include <QPainter>
#include <QGraphicsLineItem>
#include <QGraphicsScene>
#include "gan.h"
#include <QTimer>

//整体变量区间
QTimer *tim = new QTimer();
painter::painter(QWidget *parent)//init space
    : QDialog(parent)
    , ui(new Ui::painter)
{
    ui->setupUi(this);
    ui->OutputText->setReadOnly(true);
    ui->OutputText->append("**欢迎使用本程序**");
    connect(tim,SIGNAL(timeout()),this,SLOT(onTimeOut()));
    //开始创建整体计时器
    //变量初始化
    this->LengthGan1 = ui->GanLength1;
    this->LengthGan2 = ui->GanLength2;
    this->LengthGan3 = ui->GanLength3;
    this->LengthGan4 = ui->GanLength4;
}

painter::~painter()
{
    delete ui;
}


void painter::on_pushButton_clicked()
{
    Gan*gan = new Gan(ui->GanLength1->value(),ui->GanLength2->value(),ui->GanLength3->value(),ui->GanLength4->value(),ui);
    gan->Check();
    if(!(gan->isInputLeagal))
    {
        ui->OutputText->append("程序无法继续执行");
        return;
    }
    double TimeCount = ui->Times->value();//显示每秒钟运行的次数默认为10次
    tim->setInterval(int(1000/TimeCount));//用1秒钟除以执行次数
    tim->start();//开始执行定时器
    ui->OutputText->append("Timer start to run");
}

void painter::on_stop_clicked()
{

}

void painter::onTimeOut()
{
    QGraphicsScene *Scence = new QGraphicsScene();
    QGraphicsLineItem *Line_1 = new QGraphicsLineItem();
    Line_1->setLine(QLineF(1.2,23,22.2,4.2));
    QPen *pen = new QPen();
    pen->setColor(Qt::red);
    pen->setWidth(10);
    Line_1->setPen(*pen);
    Scence->addItem(Line_1);
    ui->graphicsView->setScene(Scence);
}
